package com.deluxelx.soul.inn.common.util;

import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * 加密工具包
 *
 * @author: zihao.liao
 * @date: 2024/1/19 15:12
 */
@Slf4j
public class EncryptionUtil {
    public static String encrypt(String... params) {
        StringBuilder encryptedMes = new StringBuilder();
        for (int i = 0; i < params.length; i++) {
            encryptedMes.append(Base64.getEncoder().encodeToString(params[i].getBytes(StandardCharsets.UTF_8)));
            if (i != params.length - 1) {
                encryptedMes.append(":");
            }
        }
        return encryptedMes.toString();
    }

    public static String chatRoomEncrypt(String var1, String var2) {
        try {
            long long1 = Long.parseLong(var1);
            long long2 = Long.parseLong(var2);
            long min = Math.min(long1, long2);
            long max = Math.max(long1, long2);
            return min + "_" + max;
        } catch (Exception e) {
            log.error("聊天室id加密失败，Long.valueOf(var)不符合");
            return null;
        }
    }

}
